package org.linlinjava.litemall.web.controller;

import javax.validation.constraints.NotBlank;

import io.swagger.annotations.*;
import org.linlinjava.litemall.core.util.ResponseUtil.Response;
import org.linlinjava.litemall.web.annotation.LogAnno;
import org.linlinjava.litemall.web.annotation.LoginShop;
import org.linlinjava.litemall.web.service.WebMemberService;
import org.linlinjava.litemall.web.vo.MemberQueryResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 会员控制器
 *
 * @author yliyun
 * @description：会员
 * @date 2022/09/14
 */
@Api(tags="会员操作API")
@RestController
@RequestMapping("/web/member")
@Validated
public class WebMemberController {
    /**
     * 会员服务
     */
    @Autowired
    private WebMemberService memberService;

    /**
     * 查询
     *
     * @param condition 条件
     * @return {@link Response}<{@link MemberQueryResponseVO}>
     */
    @ApiOperation(value="会员扫码 -「搜索｜会员号」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "condition",value = "会员号")
    })
    @GetMapping("/query")
    @LogAnno
    public Response query(@RequestParam("condition") String condition,@ApiIgnore @LoginShop Integer shopId){
        return memberService.query(condition,shopId);
    }

    @ApiOperation(value = "会员扫码-「查看优惠券」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "membershipNumber",value = "用户会员码"),
            @ApiImplicitParam(name = "goodsIds",value = "商品idS"),
            @ApiImplicitParam(name = "limit",value = "limit"),
            @ApiImplicitParam(name = "page",value = "page")
    })
    @GetMapping("queryCoupons")
    @LogAnno
    public Response queryCoupons(@RequestParam("membershipNumber")String membershipNumber,
                                 @RequestParam("limit")Integer limit,
                                 @RequestParam("page")Integer page,
                                 @RequestParam(value = "goodsIds",required = false) List<Integer> goodsIds,
                                 @ApiIgnore @LoginShop Integer shopId){
        return memberService.queryCoupons(membershipNumber, limit, page ,shopId,goodsIds);
    }


    @ApiOperation(value = "会员扫码-「查看礼物卡」")
    @ApiImplicitParam(name = "membershipNumber",value = "用户会员码")
    @GetMapping("queryGifts")
    @LogAnno
    public Response queryGifts(@RequestParam("membershipNumber")String membershipNumber){
        return memberService.queryGifts(membershipNumber);
    }


    @ApiOperation(value = "会员扫码-「查看付费会员」")
    @ApiImplicitParam(name = "membershipNumber",value = "用户会员码")
    @GetMapping("queryPayMember")
    @LogAnno
    public Response queryPayMember(@RequestParam("membershipNumber")String membershipNumber, @ApiIgnore @LoginShop Integer shopId){
        return memberService.queryPayMember(membershipNumber,shopId);
    }

}
